package com.dream.utils.date;
import java.util.Date;

import com.dream.utils.exception.BusinessException;

/**
 * populate a date from  String to Date
 * @copyright evan
 * @author evan
 * @Revision
 * @date 2012/8/18
 */
public class DateCalculateUtilsBuilder {
	
	private Date date;
	private DateCalculateUtilsBuilder(final Date date) {
		this.date = new Date(date.getTime());
	}
	/**
	 * get instance
	 * @param date
	 * @return
	 */
	public final static DateCalculateUtilsBuilder instance(Date date) {
		if(null == date){
			throw new BusinessException("date is null");
		}
		return new DateCalculateUtilsBuilder(date);
	}
	
	public Date toDate(){
		return date;
	}
	
	/**
	 * get Monday 
	 * @param date
	 * @return
	 */
	public DateCalculateUtilsBuilder getMonday(){
		date = DateCalculateUtils.getMonday(date);	
		return this;
	}
	
	/**
	 * get Sunday 
	 * @param date
	 * @return
	 */
	public DateCalculateUtilsBuilder getSunday(){
		date = DateCalculateUtils.getSunday(date);	
		return this;
	}
	
	/**
	 * 
	 * @param date
	 * @param week
	 * @return
	 */
	public DateCalculateUtilsBuilder getWeekByAdjust(WeekType week){
		date = DateCalculateUtils.getWeekByAdjust(date,week);	
		return this;
	}
	
	/**
	 * add some years
	 * @param date
	 * @param years
	 * @return
	 */
	public DateCalculateUtilsBuilder addYears(int years){
		date = DateCalculateUtils.addYears(date,years);	
		return this;
	}
	/**
	 * add some month
	 * @param date
	 * @param month
	 * @return
	 */
	public DateCalculateUtilsBuilder addMonths( int month){
		date = DateCalculateUtils.addMonths(date,month);	
		return this;
	}
	
	/**
	 * 
	 * @param date
	 * @param week
	 * @return
	 */
	public DateCalculateUtilsBuilder addWeeks( int week) {
		date = DateCalculateUtils.addWeeks(date,week);	
		return this;
	}
	
	/**
	 * add some day
	 * @param date
	 * @param day
	 * @return
	 */
	public DateCalculateUtilsBuilder addDays( int day) {
		
		date = DateCalculateUtils.addDays(date,day);	
		return this;
	}
	
	/**
	 * add some hours
	 * @param date
	 * @param hour
	 * @return
	 */
	public DateCalculateUtilsBuilder addHours( int hour) {

		date = DateCalculateUtils.addHours(date,hour);	
		return this;
	}


	/**
	 * add some minute
	 * @param date
	 * @param min
	 * @return
	 */
	public DateCalculateUtilsBuilder addMinutes( int min) {

		date = DateCalculateUtils.addMinutes(date,min);	
		return this;
	}

	/**
	 * 
	 * @param date
	 * @param sec
	 * @return
	 */
	public DateCalculateUtilsBuilder addSeconds( int sec) {

		date = DateCalculateUtils.addSeconds(date,sec);	
		return this;
	}

	
	/**
	 * the begin point of this day
	 * @param date
	 * @param pattern
	 * @return
	 */
	public DateCalculateUtilsBuilder toBeginPointDay() {

		date = DateCalculateUtils.toBeginPointDay(date);	
		return this;

	}
	
	/**
	 * to time 8:30 AM from initial time
	 * 
	 * @return
	 */
	public DateCalculateUtilsBuilder toTime830() {
		
		date = DateCalculateUtils.toTime830(date);	
		return this;
		
	}
	
	/**
	 * the noon point of this day
	 * @return
	 */
	public DateCalculateUtilsBuilder toMiddlePointDay() {

		date = DateCalculateUtils.toMiddlePointDay(date);	
		return this;

	}
	
	/**
	 * the end point of this day
	 * @return
	 */
	public DateCalculateUtilsBuilder toEndPointDay() {

		date = DateCalculateUtils.toEndPointDay(date);	
		return this;
	}

	
	/**
	 * first day of this year
	 * @param date
	 * @return
	 */
	public DateCalculateUtilsBuilder toYearBegin() {
		date = DateCalculateUtils.toYearBegin(date);	
		return this;
	}

	/**
	 * last day of year
	 * @return
	 */
	public DateCalculateUtilsBuilder toYearEnd() {
		date = DateCalculateUtils.toYearEnd(date);	
		return this;
	}
	
	/**
	 * first day of month
	 * @return
	 */
	public DateCalculateUtilsBuilder  toMonthBegin() {
		
		date = DateCalculateUtils.toMonthBegin(date);	
		return this;
	}

	/**
	 * last day of month
	 * @return
	 */
	public DateCalculateUtilsBuilder toMonthEnd() {
		
		date = DateCalculateUtils.toMonthEnd(date);	
		return this;
	}
	
	/**
	 * first day of this week
	 * @return
	 */
	public DateCalculateUtilsBuilder toWeekBegin() {

		date = DateCalculateUtils.toWeekBegin(date);	
		return this;

	}
	
	/**
	 * last day of this week
	 * @return
	 */
	public DateCalculateUtilsBuilder toWeekEnd(){
		date = DateCalculateUtils.toWeekEnd(date);	
		return this;
	}
}
